package com.education.welco.service.impl;


import com.education.common.utils.Convert;
import com.education.welco.mapper.SCatalogWorkMapper;
import com.education.welco.pojo.SCatalogWork;
import com.education.welco.pojo.TClass;
import com.education.welco.pojo.vo.SCatalogWorkApp;
import com.education.welco.pojo.vo.StudentWorkVo;
import com.education.welco.pojo.vo.WholeWorkInfoApp;
import com.education.welco.service.ISCatalogWorkService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 课程作业 服务层实现
 *
 * @author d
 * @date 2020-05-08
 */
@Service
public class SCatalogWorkServiceImpl implements ISCatalogWorkService {

    @Autowired
    private SCatalogWorkMapper sCatalogWorkMapper;


    /**
     * 查询课程作业信息
     *
     * @param list 课程作业ID
     * @return 课程作业信息
     */
    @Override
    public List<SCatalogWork> selectSCatalogWorkByIds(List<Integer> list) {
        return sCatalogWorkMapper.selectSCatalogWorkByIds(list);
    }

    /**
     * 查询课程作业信息
     *
     * @param id 课程作业ID
     * @return 课程作业信息
     */
    @Override
    public SCatalogWork selectSCatalogWorkById(Integer id) {
        return sCatalogWorkMapper.selectSCatalogWorkById(id);
    }

    /**
     * 查询课程作业信息
     *
     * @param catalogId 课程作业ID
     * @return 课程作业信息
     */
    @Override
    public List<SCatalogWork> selectSCatalogWorkByCatalogId(Integer catalogId) {
        return sCatalogWorkMapper.selectSCatalogWorkByCatalogId(catalogId);
    }

    /**
     * 查询课程作业列表
     *
     * @param sCatalogWork 课程作业信息
     * @return 课程作业集合
     */
    @Override
    public List<SCatalogWork> selectSCatalogWorkList(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.selectSCatalogWorkList(sCatalogWork);
    }

    /**
     * 新增课程作业
     *
     * @param sCatalogWork 课程作业信息
     * @return 结果
     */
    @Override
    public int insertSCatalogWork(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.insertSCatalogWork(sCatalogWork);
    }

    @Override
    public int deleteSCatalogWorkById(Integer id) {
        return sCatalogWorkMapper.deleteSCatalogWorkById(id);
    }

    /**
     * 修改课程作业
     *
     * @param sCatalogWork 课程作业信息
     * @return 结果
     */
    @Override
    public int updateSCatalogWork(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.updateSCatalogWork(sCatalogWork);
    }

    /**
     * 删除课程作业对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSCatalogWorkByIds(String ids) {
        return sCatalogWorkMapper.deleteSCatalogWorkByIds(Convert.toStrArray(ids));
    }

    @Override
    public List<SCatalogWork> selectCatalogWorkStuList(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.selectCatalogWorkStuList(sCatalogWork);
    }

    @Override
    public List<SCatalogWork> selectSCatalogWorkAllList(SCatalogWork catalogWork) {
        return sCatalogWorkMapper.selectSCatalogWorkAllList(catalogWork);
    }

    /**
     * 查所有二级目录下的作业列表
     * <p>
     * 课程0级id  找所有的二级目录
     * 班级id     找特定班级可以查看的作业
     * 用户id     根据学生作业表的数据判断作业的当前状态 [作业当前状态   待提交(未查到)、批改中1、驳回2、已完成3]
     * sCatalogWork.setStuId(stuId);
     * sCatalogWork.setIsStu("1");
     * sCatalogWork.setClassId(classId);
     * sCatalogWork.setTwoIDList(twoIntList);
     */
    @Override
    public List<SCatalogWork> selectSCatalogWorkStuList(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.selectSAnsweringStuList(sCatalogWork);
    }

    @Override
    public List<Integer> selectSCatalogWorkStuListAll(SCatalogWork sCatalogWork) {
        return sCatalogWorkMapper.selectSCatalogWorkStuListAll(sCatalogWork);
    }

    @Override
    public List<Integer> selectSCatalogWorkStuListSome(String courseId, Integer stuId) {
        return sCatalogWorkMapper.selectSCatalogWorkStuListSome(courseId, stuId);
    }

    @Override
    public List<SCatalogWork> selectSCatalogWorkStuListOther(List<Integer> other) {
        return sCatalogWorkMapper.selectSCatalogWorkStuListOther(other);
    }

    @Override
    public List<SCatalogWork> workListByTeacher(Integer teaId, String workName, Integer workState, Integer classId, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        return sCatalogWorkMapper.workListByTeacher(teaId, workName, workState, classId);
    }

    @Override
    public List<TClass> selectClassByworkId(Integer workId) {
        return sCatalogWorkMapper.selectClassByworkId(workId);
    }

    @Override
    public List<TClass> classIdAndNameForWork(Integer teaId) {
        return sCatalogWorkMapper.classIdAndNameForWork(teaId);
    }

    @Override
    public List<StudentWorkVo> classWorkList(Integer teaWorkId, Integer workState, Integer pageNum, Integer pageSize) {
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        return sCatalogWorkMapper.classWorkList(teaWorkId, workState);
    }

    @Override
    public StudentWorkVo workByworkIdandUserId(Integer id) {
        return sCatalogWorkMapper.workByworkIdandUserId(id);
    }

    @Override
    public int workMarkById(Integer id, BigDecimal score, String remark, Integer state) {
        return sCatalogWorkMapper.workMarkById(id, score,remark,state);
    }

    @Override
    public List<TClass> selectClassByTopCatalogId(Integer topCatalogId) {
        return sCatalogWorkMapper.selectClassByTopCatalogId(topCatalogId);
    }

    @Override
    public List<TClass> selectClassByTeaId(Integer teaId) {
        return sCatalogWorkMapper.selectClassByTeaId(teaId);
    }

    @Override
    public List<Integer> workListByWorkIdandClassId(String teaWorkId) {
        return sCatalogWorkMapper.workListByWorkIdandClassId(teaWorkId);
    }

    @Override
    public int selectWaitStudentWorkNumByTeaId(String teaId) {
        return sCatalogWorkMapper.selectWaitStudentWorkNumByTeaId(teaId);
    }

    @Override
    public List<SCatalogWorkApp> selectWorkListForTea(Integer teaId) {
        return sCatalogWorkMapper.selectWorkListForTea(teaId);
    }

    @Override
    public List<WholeWorkInfoApp> wholeWorkInfo(Integer workId,String likeName) {
        return sCatalogWorkMapper.wholeWorkInfo(workId,likeName);
    }
}